
#include "Debug.h"
#include <sstream>
#include <string>
#include <stdlib.h>
#include <sys/stat.h>
#include <mysql.h>
#include <map>
#include <string.h>
#include <glib.h>
#include "config.h"
#include "define.h"

using namespace std;

extern "C" {
  bool simpleConsInit(char *consumer, const char* conf);
  int simpleConsFriends(char *user, GHashTable *frs);
  int simpleConsUpdate(char *user, long lt, GHashTable *frs);
  void simpleConsShutdown();
  void simpleConsFlush(char *consumer);
};

bool simpleConsInit(char *consumer, const char* conf)
{
        struct stat st;
        if (lstat(conf, &st) != 0)
        {
                ERRO<<":"<<conf<<" is not exist!"<<endl;
                return false;
        }
        Configure cfg;
        map <string, string > g_Confs;
        g_Confs = cfg.LoadConfInfo(conf);
        cfg.Print();
        if(g_Confs.size() <= 0)
        {
                cerr<<"error to explain conf :"<< conf<<endl;
                return true;
        }

        return true;
}

int simpleConsUpdate(char * user, long lt, GHashTable *frs)
{
	if(user != NULL )
	{
                int iu = atoi(user);
		FObject *fo0 = new FObject(user, 1,(char *)"测试");
		g_hash_table_insert(frs, g_strdup(user), fo0);

		for(int j = 0; j< 10; j++)
		{
			ostringstream os;
			os<<(++iu);
			FObject *fo1 = new FObject((char *) os.str().c_str(), 1, (char *)os.str().c_str());
			g_hash_table_insert(frs, g_strdup(os.str().c_str()), fo1);
		}
/*
                os.str("");
                os<< (++iu);
		FObject *fo2 = new FObject((char *) os.str().c_str(), 1, (char *)"共产党");
		g_hash_table_insert(frs, g_strdup( os.str().c_str()), fo2);
*/
	}
	return 10;
}


int simpleConsFriends(char * user,  GHashTable *frs)
{
	if(user != NULL )
	{
                int iu = atoi(user);
		FObject *fo0 = new FObject(user, 1,(char *)"测试");
		g_hash_table_insert(frs, g_strdup(user), fo0);

		for(int j = 0; j< 10; j++)
		{
			ostringstream os;
			os<<(++iu);
			FObject *fo1 = new FObject((char *) os.str().c_str(), 1, (char *)os.str().c_str());
			g_hash_table_insert(frs, g_strdup(os.str().c_str()), fo1);
		}
/*
                os.str("");
                os<< (++iu);
		FObject *fo2 = new FObject((char *) os.str().c_str(), 1, (char *)"共产党");
		g_hash_table_insert(frs, g_strdup( os.str().c_str()), fo2);
*/
	}
	return 10;
}

void simpleConsShutdown()
{
 // Do whatever to close/flush/sync the consumer's work before exit...
  //   delete gx_TxLog;
}

void simpleConsFlush(char * consumer)
{
  // If this consumer keeps statistics or writes to a tx log, then
  // flush the statistics here, otherwise do nothing.
}

